import os
def is_model_empty(model_name):
    if model_name is None or model_name=="" or model_name=="--":
        return True
    else:
        return False

def childrenDir(dir):
    modelNames = []
    for f in os.listdir(dir):
        if os.path.isdir(dir + "/" + f):
            modelNames.append(f)
    return modelNames
def parse_text(text):
    """copy from https://github.com/GaiZhenbiao/ChuanhuChatGPT/"""
    lines = text.split("\n")
    lines = [line for line in lines if line != ""]
    count = 0
    for i, line in enumerate(lines):
        if "```" in line:
            count += 1
            items = line.split('`')
            if count % 2 == 1:
                lines[i] = f'<pre><code class="language-{items[-1]}">'
            else:
                lines[i] = f'<br></code></pre>'
        else:
            if i > 0:
                if count % 2 == 1:
                    replaces=[("`", "\`"),("<", "&lt;"),(">", "&gt;"),(" ", "&nbsp;"),
                              ("*", "&ast;"),("_", "&lowbar;"),("-", "&#45;"),(".", "&#46;"),
                              ("!", "&#33;"),("(", "&#40;"),(")", "&#41;"),("$", "&#36;")
                              ]
                    for item in replaces:
                        line = line.replace(item[0], item[1])
                lines[i] = "<br>"+line
    text = "".join(lines)
    return text